import QtQuick 2.6
import Qt.labs.controls 1.0

StackView{
    id: stackView
    property bool hasDestruction: false

    function navigate(qml, properties)
    {
        if (!hasDestruction) {
            stackView.replace(Qt.resolvedUrl(qml), properties)
            return
        }

        if (stackView.currentItem.hasOwnProperty("destruction") && stackView.currentItem.destruction instanceof Function) {
            stackView.currentItem.destruction(qml, properties)
        }
    }

    onCurrentItemChanged: {
        if (stackView.currentItem.hasOwnProperty("title")) {
            window.title = stackView.currentItem.title
        }

         hasDestruction = false

         if (stackView.currentItem.hasOwnProperty("destruction") && stackView.currentItem.destruction instanceof Function) {
             hasDestruction = true
         }

        drawer.close()
    }

    Keys.onReleased: {
        if (event.key === Qt.Key_Back) {           
            event.accepted = true
        }
    }
}

